package secondriver.springsubway.event;

import org.springframework.context.ApplicationEvent;
import org.springframework.context.event.SmartApplicationListener;
import org.springframework.stereotype.Component;

/**
 * @author secondriver
 * @created 2015年4月18日 下午2:41:13
 * 
 */
@Component
public class BSmartEventListener implements SmartApplicationListener{

	/**
	 * @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent)
	 * @param event
	 */
	@Override
	public void onApplicationEvent(ApplicationEvent event) {
		System.out.println(this.getClass().getCanonicalName() + " execute");
		((HelloSource) event.getSource()).say("BSmartEventListener");
	}

	/**
	 * @see org.springframework.core.Ordered#getOrder()
	 * @return
	 */
	@Override
	public int getOrder() {
		return 2;
	}

	/**
	 * @see org.springframework.context.event.SmartApplicationListener#supportsEventType(java.lang.Class)
	 * @param eventType
	 * @return
	 */
	@Override
	public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
		return SimpleEvent.class == eventType;
	}

	/**
	 * @see org.springframework.context.event.SmartApplicationListener#supportsSourceType(java.lang.Class)
	 * @param sourceType
	 * @return
	 */
	@Override
	public boolean supportsSourceType(Class<?> sourceType) {
		return sourceType == HelloSource.class;
	}

}
